home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -seriously_amiga- / shareware / programming / other / pmdev / demos / simplemenu.c < prev    next >
C/C++ Source or Header  |  1998-01-05  |  4KB  |  135 lines

  1. //
  2. // $VER: SimpleMenu.c 2.0 (22.8.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=PMMenu("Trashcan"),
  44.             PMItem("Open"),                    PMEnd,
  45.             PMItem("Submenu"),    PM_Sub, PM_MakeMenu(
  46.                 PMItem("Testing..."),                    PMEnd,
  47.                 PMItem("...gnitseT"),                    PMEnd,
  48.                 PMEnd,
  49.             PMEnd,
  50.             PMBar,                        PMEnd,
  51.             PMItem("Snapshot"),                PMEnd,
  52.             PMItem("UnSnapshot"),                PMEnd,
  53.             PMBar,                        PMEnd,
  54.             PMItem("Leave out"),                PMEnd,
  55.             PMItem("Rename..."),                PMEnd,
  56.             PMItem("Delete"),                PMEnd,
  57.             PMBar,                        PMEnd,
  58.             PMItem("Empty"),    PM_UserData,    5,    PMEnd,
  59.             PMItem("Copy to"),    PM_Sub, PM_MakeMenu(
  60.                 PMItem("RAM:"),                    PMEnd,
  61.                 PMItem("DH0:"),                    PMEnd,
  62.                 PMItem("DH1:"),                    PMEnd,
  63.                 PMItem("DH2:"),                    PMEnd,
  64.                 PMItem("DF0:"),                    PMEnd,
  65.                 PMEnd,
  66.             PMEnd,
  67.             PMItem("Copy to"),    PM_Sub, PM_MakeMenu(
  68.                 PMItem("RAM:"),                    PMEnd,
  69.                 PMItem("DH0:"),                    PMEnd,
  70.                 PMItem("DH1:"),                    PMEnd,
  71.                 PMItem("DH2:"),                    PMEnd,
  72.                 PMItem("DH3:"),                    PMEnd,
  73.                 PMItem("DH4:"),                    PMEnd,
  74.                 PMItem("DH5:"),                    PMEnd,
  75.                 PMItem("RAD:"),                    PMEnd,
  76.                 PMItem("DF0:"),                    PMEnd,
  77.                 PMItem("DF1:"),                    PMEnd,
  78.                 PMItem("DF2:"),                    PMEnd,
  79.                 PMItem("DF3:"),                    PMEnd,
  80.                 PMItem("PC0:"),                    PMEnd,
  81.                 PMItem("PC1:"),                    PMEnd,
  82.                 PMItem("TAPE:"),                PMEnd,
  83.                 PMItem("MAC:"),                    PMEnd,
  84.                 PMItem("CD0: :)"),                    PMEnd,
  85.                 PMEnd,
  86.             PMEnd,
  87.             PMItem("Copy to"),    PM_Sub, PM_MakeMenu(
  88.                 PMItem("RAM:Clipboards/"),            PMEnd,
  89.                 PMItem("DH0:Storage/DOSDrivers/"),        PMEnd,
  90.                 PMEnd,
  91.             PMEnd,
  92.             PMItem("Copy to"),    PM_Sub, PM_MakeMenu(
  93.                 PMItem("RAM:"),                    PMEnd,
  94.                 PMItem("DH0:"),                    PMEnd,
  95.                 PMEnd,
  96.             PMEnd,
  97.             End;
  98.  
  99.         if(p) {
  100.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  101.                     WA_RMBTrap,    TRUE,
  102.                     WA_DragBar,    TRUE,
  103.                     WA_Width,    150,
  104.                     WA_Height,    100,
  105.                     WA_Left,    150,
  106.                     WA_Top,        0,
  107.                     WA_Title,    "SimpleMenu",
  108.                     WA_CloseGadget,    TRUE,
  109.                     TAG_DONE);
  110.             if(w) {
  111.                 while(r) {
  112.                     WaitPort(w->UserPort);                        // Wait for a message
  113.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  114.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  115.                         ReplyMsg((struct Message *)im);                // Reply the message
  116.  
  117.                         switch(imsg.Class) {
  118.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  119.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  120.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  121.                                         PM_Menu,        p,
  122.                                         PM_Code,        imsg.Code,    // Must always be there!
  123.                                         TAG_DONE))-5);
  124.                             break;
  125.                         }
  126.                     }
  127.                 }
  128.                 CloseWindow(w);
  129.             } else printf("Window error!\n");
  130.             PM_FreePopupMenu(p);
  131.         } else printf("Menu error!\n");
  132.         CloseLibrary((struct Library *)PopupMenuBase);
  133.     }
  134. }
  135.